﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

namespace foxAudio2Word
{
    public partial class foxConfigForm : Form
    {
        public foxConfigForm()
        {
            InitializeComponent();
            //读取百度Akey和Skey
            try
            {
                // 创建一个 StreamReader 的实例来读取文件 
                // using 语句也能关闭 StreamReader
                using (StreamReader sr = new StreamReader("百度ASkey.txt"))
                {
                    foxConfigClass.myAPIKey = sr.ReadLine();
                    foxConfigClass.mySecretKey = sr.ReadLine();
                    //显示Key值
                    TBAPIKeyStr.Text = foxConfigClass.myAPIKey;
                    TBSecretKeyStr.Text = foxConfigClass.mySecretKey;
                }
            }
            catch (Exception e)
            {
                // 向用户显示出错消息
                Console.WriteLine("文件不可读：");
                Console.WriteLine(e.Message);
            }

        }

        private void BtConfig_Click(object sender, EventArgs e)
        {
            if (TBAPIKeyStr.Text == string.Empty ||
                TBSecretKeyStr.Text == string.Empty)
            {
                MessageBox.Show("百度API Key或者Secret Key不能设置为空");
                return;
            }
            //设置AKey和SKey
            using (StreamWriter sw = new StreamWriter("百度ASkey.txt", false))
            {
                sw.WriteLine(TBAPIKeyStr.Text);
                sw.WriteLine(TBSecretKeyStr.Text);
            }
            MessageBox.Show("设置成功！");
        }
    }
}
